<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <script>
    //例1
    let node = {
      type: "Identifier",
      name: "foo",
      loc: {
        start: { line: 1, column: 1 },
        end: { line: 1, column: 4 }
      },
      range: [0, 3]
    };

    let {
      loc: { start },
      range: [startIndex]
    } = node;

    console.log(start.line); // 1
    console.log(start.column); // 1
    console.log(startIndex); // 0


    //例2
    let obj = { p: ['Hello', { y: 'World' }] };

    //对象、数组层次也需要匹配
    let { p, p: [x, { y }] } = obj;
    x // "Hello"
    y // "World"
    p // ["Hello", {y: "World"}]
  </script>
</body>

</html>